var path = require('path')
var express = require('express')
var webpack = require('webpack')
var config = require('./webpack.config.dev')

var app = express()
var compiler = webpack(config)
var port = process.env.PORT || process.env.npm_package_config_port || 3000

app.use(require('webpack-dev-middleware')(compiler, {
  publicPath: config.output.publicPath,
  noInfo: config.noInfo,
  stats: config.stats
  // historyApiFallback: true,
}))

app.use(require('webpack-hot-middleware')(compiler))

// app.use(require('compression')())
app.use(express.static(__dirname))

app.get('*', function (req, res) {
  res.sendFile(path.join(__dirname, 'index.html'))
})

app.listen(port, function (err) {
  if (err) {
    console.log(err)
    return
  }

  console.log(`Listening at http://localhost:${port}`)
})
